﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Customer_Profile.eCardReport.DBDao;
using KVB.Common;
using System.Text;
using Customer_Profile.eCard.DBDao;


namespace Customer_Profile.eCardReport
{
    public partial class CapitalPressure_Report : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Comm.BindDll(ref dropEntity, "Entity", true, "");
                DataSet dsEntity = EntityDao.getEntityList("N");
                dropEntity.DataSource = dsEntity;
                dropEntity.DataTextField = "entity_name";
                dropEntity.DataValueField = "entity_id";
                dropEntity.DataBind();
                ListItem liAll = new ListItem();
                liAll.Text = "All";
                liAll.Value = "All";
                dropEntity.Items.Insert(0, liAll);

                DataSet dsProd = ProductDao.getAllProduct("ALL");
                dropProd.DataSource = dsProd;
                dropProd.DataTextField = "procduct_name";
                dropProd.DataValueField = "procduct_code";
                dropProd.DataBind();
                ListItem liAllprod = new ListItem();
                liAllprod.Text = "All";
                liAllprod.Value = "All";
                dropProd.Items.Insert(0, liAllprod);

                txtgedatebegin.Text = DateTime.Now.ToString("yyyy-MM-dd");
                txtgedateend.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
            BindDataView();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

        }

        private string GetWhere()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" where d.if_refund='N' ");

                if (txtgedatebegin.Text.Trim() != "" && txtgedateend.Text.Trim() != "")
                {
                    string strStartDate = txtgedatebegin.Text;
                    string strEndDate = txtgedateend.Text;
                    sb.Append(" AND convert(date,value_date) between '" + strStartDate + "' and '" + strEndDate + "' ");
                }
                if (dropEntity.SelectedIndex > 0)
                {
                    sb.Append(" And d.entity_id='" + dropEntity.SelectedItem.Value.Trim() + "'");
                }

                if (dropProd.SelectedIndex > 0)
                {
                    string strDropProdcode = dropProd.SelectedItem.Value;
                    sb.Append(" And d.prod_code='" + strDropProdcode + "'");
                }
                sb.Append(" order by d.value_date");
                return sb.ToString();
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("DailyReportGetWhere", ex.ToString());
                return "";
            }
        }

        private void BindDataView()
        {
            string sWhere = this.GetWhere();
            try
            {
                DataSet ds = ReportDao.GetRemitReport(sWhere);
                if (ds != null && ds.Tables.Count > 0)
                {
                    ASPxGridView1.DataSource = ds.Tables[0];
                    ASPxGridView1.DataBind();
                }
                //else
                //{
                //    ASPxGridView1.DataBind();
                //}
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("Maturity_BindDataView", ex.ToString());
            }
        }
    }
}